package com.archie.zhufengfm.tasks;

/**
 * Created by Archie on 2015/10/20.
 */

import android.os.AsyncTask;
import android.util.Log;

import com.archie.zhufengfm.Constants;
import com.archie.zhufengfm.client.ClientAPI;
import com.archie.zhufengfm.utils.EntityParseUtil;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 发现部分分类的数据加载异步任务
 */
public class DiscoverCategoryTask extends BaseTask {

    public DiscoverCategoryTask(TaskCallback callback) {
        super(callback);
    }

    @Override
    protected TaskResult doInBackground(String... params) {
        TaskResult ret = new TaskResult();

        ret.action = Constants.TASK_ACTION_DISCOVER_CATEGORIES;

        JSONObject jsonObject = ClientAPI.getDiscoverCategories();

        if (jsonObject != null) {
            try {

                ret.resultCode = jsonObject.getInt("ret");
                ret.data = EntityParseUtil.parseDiscoverCategory(jsonObject);

            } catch (JSONException e) {
                e.printStackTrace();
            }

        }

        return ret;
    }
}
